<?php

function login(){
	if (isset($_SESSION['username']))
			{
				echo 'Welcome, '.$_SESSION['firstname'];
				echo '<br><a href="myprofile.php">My Account</a>';
                                echo '<form action="user/logout.php">
                                        <input type="submit" name="Submit" value="Logout">
                                        </form>';
			}
			else{
				echo
					'<form action="user/login.php" method="post">
					username: <input type="text" name="username"><br>
					password: <input type="password" name="password">
					<input type="submit" name="Submit" value="Login">
					</form>
					<a href="registration.php">Not a user?</a>';
			}
}

function logout(){
   session_start();
    $_SESSION['id'] = null;
    $_SESSION['logged'] = null;

    unset($_SESSION);

    session_destroy();
}

function check_level(){
      if($_SESSION['level'] == 1){
             return 1;
      }
      else{
             return 0;
      }
}

function display_search(){
	echo '<form action="search.php" method="get">
		  <select name="search">
			  <option value="test">Test Category</option>
		  </select>
		  <input type="text" name="manual_search" size="50">
		  <input type="submit" name="Search" value="Search">
		  </form>';
}

function send_email($email,$hash,$password,$username){
	$from = "Hyrule Sports <noreply@hyrulesports.com>";
	$to = "name <$email>";
	$subject = 'Verification E-mail';
	$host = 'hyrulesports.com';
	$body = '
	
	Thank you for signing up!
	
	Your account has been created. You can login with the following credentials after your account has been verified.
	
	---------------------------
	Username: '.$username.'
	Password: '.$password.'
	---------------------------
	
	Please click this link to activate your account:
	
	http://www.hyrulesports.com/verify.php?email='.$email.'&hash='.$hash.'';
	
	$headers = array ('From' => $from,
		'To' => $to,
		'Subject' => $subject);
	$smtp = Mail::factory('smtp', 
		array ('host' => $host,
		'auth' => true,
		'username' => 'noreply@hyrulesports.com',
		'password' => 'TestEmail1'));
	
	$mail = $smtp->send($to, $headers, $body);
 
 if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  }
}

function list_states(){
echo '
	<select name="state">
		<option value="AL">AL</option>
		<option value="AK">AK</option>
		<option value="AZ">AZ</option>
		<option value="AR">AR</option>
		<option value="CA">CA</option>
		<option value="CO">CO</option>
		<option value="CT">CT</option>
		<option value="DE">DE</option>
		<option value="DC">DC</option>
		<option value="FL">FL</option>
		<option value="GA">GA</option>
		<option value="HI">HI</option>
		<option value="ID">ID</option>
		<option value="IL">IL</option>
		<option value="IN">IN</option>
		<option value="IA">IA</option>
		<option value="KS">KS</option>
		<option value="KY">KY</option>
		<option value="LA">LA</option>
		<option value="ME">ME</option>
		<option value="MD">MD</option>
		<option value="MA">MA</option>
		<option value="MI">MI</option>
		<option value="MN">MN</option>
		<option value="MS">MS</option>
		<option value="MO">MO</option>
		<option value="MT">MT</option>
		<option value="NE">NE</option>
		<option value="NV">NV</option>
		<option value="NH">NH</option>
		<option value="NJ">NJ</option>
		<option value="NM">NM</option>
		<option value="NY">NY</option>
		<option value="NC">NC</option>
		<option value="ND">ND</option>
		<option value="OH">OH</option>
		<option value="OK">OK</option>
		<option value="OR">OR</option>
		<option value="PA">PA</option>
		<option value="RI">RI</option>
		<option value="SC">SC</option>
		<option value="SD">SD</option>
		<option value="TN">TN</option>
		<option value="TX">TX</option>
		<option value="UT">UT</option>
		<option value="VT">VT</option>
		<option value="VA">VA</option>
		<option value="WA">WA</option>
		<option value="WV">WV</option>
		<option value="WI">WI</option>
		<option value="WY">WY</option>
	</select>';

}
?>
